import { createRouter, createWebHistory } from 'vue-router'
import {useUserStore} from '@/stores/user.js'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path:'/login',component:() => import('@/views/before/LoginPage.vue')},
    {
      path:'/',
      component: () => import('@/views/after/layout/LayoutContainer.vue'),
      redirect:'/dashboard',
      children:[
        {
          path:'dashboard',
          component: () => import('@/views/after/dashboard/DashBoardPage.vue')
        },


        {
          path:'resource/student/work',
          component: () => import('@/views/after/resource/StudentHomeWork.vue')
        },
        {
          path:'resource/course',
          component: () => import('@/views/after/resource/CourseResourcePage.vue')
        },
        {
          path:'resource/course/star',
          component: () => import('@/views/after/resource/CourseStarPage.vue')
        },


        {
          path:'class/student/leave',
          component: () => import('@/views/after/class/StudentLeavePage.vue')
        },
        {
          path:'class/student/info',
          component: () => import('@/views/after/class/StudentInfoPage.vue')
        },


        {
          path:'course/info',
          component: () => import('@/views/after/course/CourseInfoPage.vue')
        },
        {
          path:'course/sub/info',
          component: () => import('@/views/after/course/CourseSubInfoPage.vue')
        },
        {
          path:'course/schedule',
          component: () => import('@/views/after/course/CourseSchedulePage.vue')
        },


        {
          path:'exam/schedule',
          component: () => import('@/views/after/exam/ExamSchedulePage.vue')
        },
        {
          path:'exam/paper',
          component: () => import('@/views/after/exam/ExamPaperPage.vue')
        },
        {
          path:'exam/watch',
          component: () => import('@/views/after/exam/WatchExamPaper.vue')
        },


        {
          path:'company/info',
          component: () => import('@/views/after/company/CompanyPage.vue')
        },
        {
          path:'company/student',
          component: () => import('@/views/after/company/CompanyStudent.vue')
        },



        {
          path:'other/sys/log',
          component: () => import('@/views/after/sys/SysLog.vue')
        },
        {
          path:'other/sys/info',
          component: () => import('@/views/after/sys/SysInfo.vue')
        },
        {
          path:'other/sys/device',
          component: () => import('@/views/after/sys/SysDevice.vue')
        },





      ]
    },

    {
      path:'/main',
      component: () => import('@/views/before/layout/LayoutContainer.vue'),
      redirect:'/main/task',
      children:[
        {
          path:'task',
          component: () => import('@/views/before/task/TaskPage.vue')
        },
        {
          path:'taskDetail',
          component: () => import('@/views/before/task/TaskDetailPage.vue')
        },
        {
          path:'exam',
          component: () => import('@/views/before/task/ExamPage.vue')
        },
        
        {
          path:'person/self',
          component: () => import('@/views/before/person/SelfPerson.vue')
        }
      ]
    }
  ]
})

router.beforeEach( (to) => {
  const userStore = useUserStore()
  console.log("usertoken"+userStore.token)
  if(!userStore.token && to.path !== '/login'){
      return '/login'
  }
  return true
})

export default router
